import Picker from "react-native-picker";
import station from "../json/station.json";

const data = [];

export default function showStationPicker() {
  return new Promise((resolve, reject) => {
    if (data.length === 0) {
      const len = station.length;
      for (let i = 0; i < len; i += 1) {
        const item = {};
        item[station[i].name] = station[i].station;
        data.push(item);
      }
    }
    Picker.init({
      pickerData: data,
      pickerConfirmBtnText: "确定",
      pickerCancelBtnText: "取消",
      pickerTitleText: "请选择地铁站",
      pickerToolBarBg: [255, 255, 255, 1],
      pickerBg: [255, 255, 255, 1],
      selectedValue: ["一号线", "呼兰路"],
      onPickerConfirm: pickedValue => {
        resolve(pickedValue);
      },
      onPickerCancel: pickedValue => {
        reject(pickedValue);
      },
    });
    Picker.show();
  });
}
